import datetime
import random


class NumGame(object):

    def __init__(self):
        self.history = {}
        self.name_guess_map = {}
        self.num_limit = 20
        self.play_num = 0
        self.answer = random.randint(0, 1024)

    def game_begin(self):
        name = input("用户名：")
        self.history[name] = self.name_guess_map
        while True:
            select = input("1.历史记录\n2.继续游戏\n3.停止游戏\n输入你选择的数字：")
            if select == "3":
                print("退出游戏。")
                break
            elif select == "1":
                print("查询历史记录：")
                for name, value in self.history.items():
                    for num, time in value.items():
                        print("{}输出了{},输出时间：{}".format(name, num, time))
                    print()
            elif select == "2":
                self.guess_num(name)

    def guess_num(self, name):
        input_num = input("请猜一个数：")
        now_time = datetime.datetime.now().time()
        self.name_guess_map[input_num] = now_time
        if int(input_num) < self.answer:
            self.play_num += 1
            print("小了!剩余猜测次数：{}次".format(self.num_limit - self.play_num))
        elif int(input_num) > self.answer:
            self.play_num += 1
            print("大了!剩余猜测次数：{}次".format(self.num_limit - self.play_num))
        elif int(input_num) == self.answer:
            print("恭喜！猜对了，正确答案是{}!".format(self.answer))
        else:
            print("Game Over!剩余次数：{}".format(self.num_limit - self.play_num))


NumGame().game_begin()
